PariahCybersecTest.AccountsWithSessionsTest

Tests all of the AccountsWithSessions system

 public static async Task AccountsWithSessionsTest()
{
    var directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PariahCybersecTest", "TestFilesAsync");

    if (Directory.Exists(directory))
    {
        Directory.Delete(directory, true); 
        Console.WriteLine("Directory and its contents reset.");
    }

    Directory.CreateDirectory(directory);

    Console.WriteLine(directory);
    string username = "testUser";
    var password = "testPassword123".ToSecureData(); // Convert to SecureString
    string recoveryPassword = "recoveryPassword123"; // Recovery password

    // Initialize the object that has the methods
    var userManagement = new DataHandler.AccountsWithSessions();

    // Setup files (Initialize JSON structure)
    await userManagement.SetupFiles(directory);

    // Create a user
    var recoveryKey = await userManagement.CreateUser(username, password, directory);
    Console.WriteLine($"User created. Recovery key: {recoveryKey.ConvertToString()}");

    // Login the user
    var loginResult = await userManagement.LoginUser(username, directory, password, true);
    Console.WriteLine($"User logged in. Session ID: {loginResult.Item2.SessionID}");

    // Validate the session
    bool isSessionValid = await userManagement.ValidateSession(loginResult.Item2, loginResult.Item1);
    Console.WriteLine($"Is session valid: {isSessionValid}");

    // Reset password
    var newPassword = "newPassword123".ToSecureData();
    await userManagement.ResetPassword(loginResult.Item2, loginResult.Item1, newPassword, recoveryKey);
    Console.WriteLine("Password reset successfully.");

    // Logout user (Remove if testing remove account, you need to be logged in to remove your acc)
    await userManagement.LogoutUser(loginResult.Item2, loginResult.Item1);
    Console.WriteLine("User logged out.");

    // Remove account
    await userManagement.RemoveAccount(loginResult.Item2, loginResult.Item1);
    Console.WriteLine("Account removed successfully.");
}